package com.qf.service.impl;

import com.qf.dao.OrderDetailDao;
import com.qf.dao.impl.OrderDetailDaoimpl;
import com.qf.domain.Address;
import com.qf.domain.Goods;
import com.qf.domain.Order;
import com.qf.domain.OrderDetail;
import com.qf.service.AddressService;
import com.qf.service.GoodsService;
import com.qf.service.OrderDetailService;
import com.qf.service.OrderService;

import java.util.List;

public class OrderDetailServiceimpl implements OrderDetailService {
    private OrderDetailDao orderDetailDao=new OrderDetailDaoimpl();
    @Override
    public void addOrderDetail(OrderDetail orderDetail) {

        orderDetailDao.addOrderDetailimpl(orderDetail);
    }

    @Override
    public OrderDetail selectOrderDetailOne(String oid) {
        OrderDetailDao orderDetailDao=new OrderDetailDaoimpl();
        OrderDetail orderDetail=orderDetailDao.selectOrderDetailOne(oid);
        OrderService orderService=new OrderServiceimpl();
        Order order=orderService.selectIdOne(orderDetail.getOid());
        orderDetail.setOrder(order);


        AddressService addressService=new AddressServiceimpl();
        Address address = addressService.selectUserAddressOne(order.getAid());
        orderDetail.setAddress(address);

        GoodsService goodsService=new GoodsServiceImpl();
        Goods byid = goodsService.findByid(orderDetail.getPid());
        orderDetail.setGoods(byid);
        return orderDetail;
    }

    @Override
    public List<OrderDetail> selectOrderDetailAll(String oid) {
        OrderDetailDao orderDetailDao=new OrderDetailDaoimpl();
        List<OrderDetail> list=orderDetailDao.selectOrderDetailAll(oid);
        for (OrderDetail orderDetail:list){
            OrderService orderService=new OrderServiceimpl();
            Order order=orderService.selectIdOne(orderDetail.getOid());
            orderDetail.setOrder(order);


            AddressService addressService=new AddressServiceimpl();
            Address address = addressService.selectUserAddressOne(order.getAid());
            orderDetail.setAddress(address);

            GoodsService goodsService=new GoodsServiceImpl();
            Goods byid = goodsService.findByid(orderDetail.getPid());
            orderDetail.setGoods(byid);
        }
        return list;
    }
}
